

package com.jfinal.aceadmin.model;

import com.jfinal.ext.plugin.tablebind.TableBind;

import com.jfinal.plugin.activerecord.Db;

import java.util.ArrayList;
import java.util.List;

/**
 * <a href="UserTask.java.html"><b><i>View Source</i></b></a>
 *
 * @author Jason
 *
 */
@TableBind(tableName = "UserTask", pkName = "baseId")
public class UserTask extends BaseModel<UserTask> {
	private static final long serialVersionUID = 1L;
	public static UserTask dao = new UserTask();

	public long getBaseId() {
		return this.get("baseId");
	}

	public void setBaseId(long baseId) {
		this.set("baseId", baseId);
	}

	public int getUserId() {
		return this.get("userId");
	}

	public void setUserId(int userId) {
		this.set("userId", userId);
	}

	public String getDescription() {
		return this.get("description");
	}

	public void setDescription(String description) {
		this.set("description", description);
	}

	public int getRate() {
		return this.get("rate");
	}

	public void setRate(int rate) {
		this.set("rate", rate);
	}

	public List<UserTask> findByUserId(int userId) {
		List<UserTask> result = new ArrayList<UserTask>();
		StringBuilder sBuilder = new StringBuilder(
				"SELECT * FROM UserTask WHERE ");
		sBuilder.append("userId = ?");

		result = UserTask.dao.find(sBuilder.toString(), userId);

		return result;
	}

	public int countByUserId(int userId) {
		int result = 0;
		StringBuilder sBuilder = new StringBuilder(
				"SELECT COUNT(*) FROM UserTask WHERE ");
		sBuilder.append("userId = ?");
		result = Db.queryLong(sBuilder.toString(), userId).intValue();

		return result;
	}

	public List<UserTask> findByUserIdAndProgress(int userId, int rate) {
		List<UserTask> result = new ArrayList<UserTask>();
		StringBuilder sBuilder = new StringBuilder(
				"SELECT * FROM UserTask WHERE ");
		sBuilder.append("userId = ?");
		sBuilder.append(" AND ");
		sBuilder.append("rate = ?");

		result = UserTask.dao.find(sBuilder.toString(), userId, rate);

		return result;
	}

	public int countByUserIdAndProgress(int userId, int rate) {
		int result = 0;
		StringBuilder sBuilder = new StringBuilder(
				"SELECT COUNT(*) FROM UserTask WHERE ");
		sBuilder.append("userId = ?");
		sBuilder.append(" AND ");
		sBuilder.append("rate = ?");
		result = Db.queryLong(sBuilder.toString(), userId, rate).intValue();

		return result;
	}
}